package com.baidu.health.checkImages;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 内容审核平台-图像 示例代码
public class sendRequest {
    public String sendRequest(String src) {

        String path = "https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        String parameters = getParameters.getParameters();
        JSONObject parseObject = JSON.parseObject(parameters);
        String accessToken = parseObject.get("access_token")+"";

        // 设置query参数
        request.addQueryParameter("access_token", accessToken);

        // 设置jsonBody参数
        String jsonBody = "imgUrl="+src;
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
            return response.getResult();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }
}